﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using VINETLIFE.BL;
using VINETLIFE.DO;
using System.Web.UI.HtmlControls;
using System.Data;

namespace VINETLIFE
{
    public partial class Article : System.Web.UI.Page
    {
        int articleId = 0;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(Request.QueryString["ID"]))
            {
                articleId = int.Parse(Request.QueryString["ID"]);
                if (!IsPostBack)
                {
                    ltrBreadcrumbs.Text = Ultility.Breadcrumb("article", articleId);
                    GetTags(articleId);
                    rptArticleDetailDataSource(articleId);
                    SEO();
                }
            }
            else
            {
                Response.Redirect("Default.aspx");
            }
        }
        private void SEO()
        {
            cmsArticleDO objArticle = new cmsArticleBL().Select(new cmsArticleDO() { ArticleID = articleId });
            if (!string.IsNullOrEmpty(objArticle.MetaTag))
            {
                HtmlMeta metaKey = new HtmlMeta();
                metaKey.Name = "keywords";
                metaKey.Content = objArticle.MetaTag;
                Page.Header.Controls.Add(metaKey);
            }
            else
            { }
            HtmlMeta metaDesc = new HtmlMeta();
            metaDesc.Name = "description";
            if (!string.IsNullOrEmpty(objArticle.MetaDes))
            {
                metaDesc.Content = objArticle.MetaDes;
            }
            else
            {
                metaDesc.Content = objArticle.Description;
            }
            Page.Header.Controls.Add(metaDesc);

            if (!string.IsNullOrEmpty(objArticle.PageTitle))
            {
                Page.Title = objArticle.PageTitle;// +" | " + Ultility.WebTitle();
            }
            else
            {
                Page.Title = objArticle.Title;// +" | " + Ultility.WebTitle();
            } rptOther.DataSource = new DataView(new cmsArticleBL().SelectByCatNum(objArticle.CategoryID, 10), "ArticleID<>" + objArticle.ArticleID.ToString(), "", DataViewRowState.CurrentRows);
            rptOther.DataBind();
        }
        private void rptArticleDetailDataSource(int articleID)
        {
            rptArticleDetail.DataSource = new cmsArticleBL().SelectByPK(articleID);
            rptArticleDetail.DataBind();
        }

        public string Tags = string.Empty;
        string GetTags(int articleID)
        {
            DataTable tb = new cmsArticleBL().GetByPK(articleID);
            if (tb.Rows.Count > 0)
            {
                DataRow dr = tb.Rows[0];
                Tags = dr["MetaTag"].ToString();
            }
            return Tags;
        }
        protected string FriendlyUrl(string strTitle)
        {
            return Ultility.Change_AV(strTitle);
        }
    }
}